package com.egao.oa.controller;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.DictionaryData;
import com.egao.common.system.service.DictionaryDataService2;
import com.egao.oa.entity.Bugs;
import com.egao.oa.entity.PhoneBook;
import com.egao.oa.service.BugsService;
import com.egao.oa.service.PhoneBookService;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 *
 * 系统测试
 * @author : Doman
 * @date : 2020-08-14 16:51:04
 * @version ：1.0
 */

@Controller
@RequestMapping("/oa/bugs")
public class BugsController extends BaseController {

	@Autowired
	private BugsService bugsService;
    @Autowired
    private DictionaryDataService2 dictionaryDataService2;
    @Autowired
    private PhoneBookService phoneBookService;
	
	/**
	 * 页面
	 **/
	@RequiresPermissions("oa:bugs:view")
	@RequestMapping()
	public String view(Model model) {
        model.addAttribute("projectsList",dictionaryDataService2.listAllByDictCode(new DictionaryData("subjects")));
        model.addAttribute("stateList",dictionaryDataService2.listAllByDictCode(new DictionaryData("bugsState")));
        model.addAttribute("typeList",dictionaryDataService2.listAllByDictCode(new DictionaryData("bugsType")));
        PhoneBook phoneBook = new PhoneBook();
        phoneBook.setAutocompletevalue("it");
        model.addAttribute("itphoneBookList",phoneBookService.list(phoneBook, getLoginUser()));
        phoneBook = new PhoneBook();
        model.addAttribute("allphoneBookList",phoneBookService.list(phoneBook, getLoginUser()));
		return "oa/bugs.html";
	}

	/**
	 * 分页查询列表
	 */
	@RequiresPermissions("oa:bugs:list")
	@OperLog(value = "系统测试", desc = "分页查询")
	@ResponseBody
	@RequestMapping("/page")
    public JsonResult list(PageResult2<T> page, Bugs bugs) throws Exception{
        return bugsService.list(page, bugs, getLoginUser());
    }

    /**
     * 查询全部系统测试
     */
    @RequiresPermissions("oa:bugs:list")
    @OperLog(value = "系统测试", desc = "查询全部")
    @ResponseBody
    @RequestMapping("/list")
    public JsonResult list(Bugs bugs){
        return JsonResult.ok().setData(bugsService.list(bugs, getLoginUser()));
    }

    /**
     * 根据id查询系统测试
     */
    @RequiresPermissions("oa:bugs:list")
    @OperLog(value = "系统测试", desc = "根据id查询")
    @ResponseBody
    @RequestMapping("/get")
    public JsonResult get(Bugs bugs) {
        return bugsService.getById(bugs);
		// 使用关联查询
        //PageParam<bugs> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<bugs> records = bugsService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加系统测试
     */
    @RequiresPermissions("oa:bugs:save")
    @OperLog(value = "系统测试", desc = "添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/save")
    public JsonResult save(Model model, Bugs bugs) {
        return bugsService.save(bugs, getLoginUser());
    }

    /**
     * 修改系统测试
     */
    @RequiresPermissions("oa:bugs:update")
    @OperLog(value = "系统测试", desc = "修改", param = false, result = true)
    @ResponseBody
    @RequestMapping("/update")
    public JsonResult update(Model model, Bugs bugs) {
        return bugsService.update(bugs, getLoginUser());
    }

    /**
     * 删除系统测试
     */
    @RequiresPermissions("oa:bugs:remove")
    @OperLog(value = "系统测试", desc = "删除", result = true)
    @ResponseBody
    @RequestMapping("/remove")
    public JsonResult remove(Bugs bugs ) {
        return bugsService.remove(bugs, getLoginUser());
    }

    /**
     * 批量添加系统测试
     */
    /**@RequiresPermissions("oa:bugs:save")
    @OperLog(value = "系统测试", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Bugs> list) {
        if (bugsService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改系统测试
     */
    /**@RequiresPermissions("oa:bugs:update")
    @OperLog(value = "系统测试", desc = "批量修改", result = true)
    @ResponseBody
    @RequestMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Bugs> batchParam) {
        if (batchParam.update(bugsService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除系统测试
     */
    /**@RequiresPermissions("oa:bugs:remove")
    @OperLog(value = "系统测试", desc = "批量删除", result = true)
    @ResponseBody
    @RequestMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (bugsService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
